// 访问 token 缓存的 key
const ACCESS_TOKEN_KEY = "access_token";
// 刷新 token 缓存的 key
const REFRESH_TOKEN_KEY = "refresh_token";

function getAccessToken(): string {
  return localStorage.getItem(ACCESS_TOKEN_KEY) || "";
}

function setAccessToken(token: string) {
  localStorage.setItem(ACCESS_TOKEN_KEY, token);
}

function getRefreshToken(): string {
  return localStorage.getItem(REFRESH_TOKEN_KEY) || "";
}

function setRefreshToken(token: string) {
  localStorage.setItem(REFRESH_TOKEN_KEY, token);
}

function clearToken() {
  localStorage.removeItem(ACCESS_TOKEN_KEY);
  localStorage.removeItem(REFRESH_TOKEN_KEY);
}

// 用户类型为3则是主播
function getUserType() {
  return localStorage.getItem("userType") || "";
}

function setUserType(type: string) {
  localStorage.setItem("userType", type);
}

function getUserBizId(): string {
  return localStorage.getItem("userBizId") || "";
}
function setUserBizId(value: string) {
  localStorage.setItem("userBizId", value);
}

export {
  getAccessToken,
  setAccessToken,
  clearToken,
  getRefreshToken,
  setRefreshToken,
  getUserType,
  setUserType,
  getUserBizId,
  setUserBizId,
};
